import RPi.GPIO as GPIO
import time

class Motor(object):
	
	def __init__(self,ain1=20,ain2=21):
		self.AIN1 = ain1
		self.AIN2 = ain2

		GPIO.setmode(GPIO.BCM)
		GPIO.setwarnings(False)
		GPIO.setup(self.AIN1,GPIO.OUT)
		GPIO.setup(self.AIN2,GPIO.OUT)
		self.stop()

	def forward(self):
		GPIO.output(self.AIN1,GPIO.LOW)
		GPIO.output(self.AIN2,GPIO.HIGH)


	def stop(self):
		GPIO.output(self.AIN1,GPIO.LOW)
		GPIO.output(self.AIN2,GPIO.LOW)

	def backward(self):
		GPIO.output(self.AIN1,GPIO.HIGH)
		GPIO.output(self.AIN2,GPIO.LOW)


if __name__=='__main__':

	M = Motor()
	M.forward()
	time.sleep(0.1)
	M.stop()
	time.sleep(1)
	M.backward()
	time.sleep(0.5)
	M.stop()

	try:
		while True:
			time.sleep(1)
			
	except KeyboardInterrupt:
		GPIO.cleanup()

